package com.liangzi.service_core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liangzi.service_core.config.TimeConfig;
import com.liangzi.service_core.mapper.InnerDoctorWorkMapper;
import com.liangzi.service_core.pojo.entity.InnerDoctor;
import com.liangzi.service_core.mapper.InnerDoctorMapper;
import com.liangzi.service_core.pojo.entity.InnerDoctorWork;
import com.liangzi.service_core.pojo.vo.InnerDoctorWorkVO;
import com.liangzi.service_core.service.InnerDoctorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 医生表 服务实现类
 * </p>
 *
 * @author zhj
 * @since 2021-12-13
 */
@Service
@Slf4j
public class InnerDoctorServiceImpl extends ServiceImpl<InnerDoctorMapper, InnerDoctor> implements InnerDoctorService {


    @Autowired
    private InnerDoctorWorkMapper innerDoctorWorkMapper;
    @Autowired
    private InnerDoctorMapper innerDoctorMapper;

    @Autowired
    private TimeConfig timeConfig;

    // 获取 排班信息
    @Override
    public ArrayList<InnerDoctorWorkVO> getDoctorWorkById(String id) {
        if(id == null){
            log.info(id + "不存在");
            return null;
        }
        QueryWrapper<InnerDoctorWork> innerDoctorQueryWrapper = new QueryWrapper<>();
        innerDoctorQueryWrapper.eq("doctor_id",id);
        innerDoctorQueryWrapper.ge("doctor_work_date",timeConfig.getCurrentTimeFormat());
        Collection<InnerDoctorWork> list = innerDoctorWorkMapper.selectList(innerDoctorQueryWrapper);
        ArrayList<InnerDoctorWorkVO> innerDoctorWorkVOS = new ArrayList<>();
        for (InnerDoctorWork innerDoctorWork : list) {
            InnerDoctorWorkVO innerDoctorWorkVO = new InnerDoctorWorkVO();
            BeanUtils.copyProperties(innerDoctorWork,innerDoctorWorkVO,InnerDoctorWorkVO.class);
            innerDoctorWorkVOS.add(innerDoctorWorkVO);
        }
        return innerDoctorWorkVOS;
    }

    @Override
    public List<InnerDoctor> getDoctorsByDictCode(Long dictCode) {
        if(dictCode == null){
            log.info(dictCode + "  不能为空");
        }
        // 根据门诊id获取该门诊的所有医生
        QueryWrapper<InnerDoctor> innerDoctorQueryWrapper = new QueryWrapper<>();
        innerDoctorQueryWrapper.eq("doctor_outpatient", dictCode);
        List<InnerDoctor> doctorList = innerDoctorMapper.selectList(innerDoctorQueryWrapper);

        return doctorList;
    }
}
